{include file="header.tpl" title=header}
{include file="types.tpl" title=types}
    <div id="loading" style="display:none"></div>
    <div id="metas">
      <div id="meta">
        <div id="baseTags">
{include file="tags.tpl" title=tags}
        </div>
      </div>
    </div>
    <div id="baseItems">
{include file="items.tpl" title=items}
    </div>
    <script type="text/javascript">
{literal}
var lastType = '';
var lastTag  = '';

var popTags = function(type)
{
	if(!type) type = '';
	$("#baseTags").slideUp("slow", function()
	{
		loading(1);
		$("#baseTags").load("index.php", {type: type, ajax: 'tags'}, function()
		{
			loading(-1);
			$("#baseTags").slideDown("slow");
		});
	});
}

var popItems = function(type, meta, page)
{
	if(!type) type = '';
	if(!meta) meta = '';
	if(!page) page = '';
	$("#baseItems").fadeOut("def", function()
	{
		loading(1);
		$("#baseItems").load("index.php", {type: type, meta: meta, page: page, ajax: 'items'}, function()
		{
			loading(-1);
			$("#baseItems").fadeIn("def");
		});
	});
}

var typeAction = function(type)
{
	$('#type li').removeClass('selected');
	if(type != lastType)
	{
		$('#type'+type).addClass('selected');
		popTags(type);
		popItems(type);
		lastType = type;
	}
	else
	{
		popTags();
		popItems();
		lastType = '';
	}
	return false;
}

var tagAction = function(meta)
{
	$('#baseTags a').removeClass('selected');
	if(meta != lastTag)
	{
		$('#meta'+meta).addClass('selected');
		popItems(lastType, meta);
		lastTag = meta;
	}
	else
	{
		popItems(lastType);
		lastTag = '';
	}
	return false;
}

var deleteTagAction = function(meta, type)
{
	if(confirm('Are you sure you whant to delete this tag ?'))
	{
		loading(1);
		$.ajax({
			type: "GET",
			url:  "do.php",
			data: "ajax=true&type"+type+"&id="+meta+"&action=deleteMeta",
			success: function(msg)
			{
				//alert( "Data Saved: " + msg );
				loading(-1);
			}
		});
		$("#meta"+meta).fadeOut("slow");
		$("#metasup"+meta).fadeOut("slow");
	}
	return false;
}

var pageAction = function(type, meta, page)
{
	if(!type) type = '';
	if(!meta) meta = '';
	popItems(type, meta, page);
	return false;
}

var prev = pageAction;
var next = pageAction;
{/literal}
    </script>
{include file="footer.tpl" title=footer}
